package com.example.crm.servlet;

import com.example.crm.pojo.Customer;
import com.example.crm.service.CustomerService;
import com.example.crm.service.impl.CustomerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author AthenaKnovesp
 */

@WebServlet(value = "/CustomerServlet3")
public class CustomerServlet3 extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        Customer customer = new Customer();
        customer.setName(req.getParameter("cust_name"));
        customer.setLevel(req.getParameter("cust_level"));
        customer.setSource(req.getParameter("cust_source"));
        customer.setLinkMan(req.getParameter("cust_linkman"));
        customer.setPhone(req.getParameter("cust_phone"));
        customer.setMobile(req.getParameter("cust_mobile"));

        CustomerService customerService = new CustomerServiceImpl();
        int i = customerService.addCustomer(customer);
        if (i == 1) {
            req.getRequestDispatcher("/WEB-INF/jsp/customer/list.jsp").forward(req, resp);
        }
    }
}